﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace QuickTuner
{
    /// <summary>
    /// Provides helper methods to keep the <see cref="Radio" /> tests DRY
    /// </summary>
    public static class RadioHelper
    {
        /// <summary>
        /// Creates a default <see cref="Radio" /> instance.
        /// </summary>
        public static Radio CreateDefaultInstance()
        {
            return new Radio();
        }

        /// <summary>
        /// Moves the CurrentStationIndex by one station further
        /// Wrapping around if index overflowed.
        /// </summary>
        /// <param name="r"></param>
        public static void NextStation(this Radio r)
        {
            r.CurrentStationIndex = (r.CurrentStationIndex + 1) % r.Stations.Count;
        }

        /// <summary>
        /// Add some stations the radio.
        /// </summary>
        public static void AddSomeStations(Radio instance, int count)
        {
            StationListHelper.AddSomeStations(instance.Stations, count);
        }

        /// <summary>
        /// Tests wether the give Radio instances' properties are equal.
        /// Does not check run-time dependent property such as IsPlaying and PlayEngine.
        /// </summary>
        /// <param name="a">The first Radio intance to test.</param>
        /// <param name="b">The second Radio instance to test.</param>
        public static bool MemberwiseEquals(Radio a, Radio b)
        {

            var result = true;

            // prop selects a property for comparison
            // then compares the selected property taken from a and b
            Action<Func<Radio, object>>
                check = prop => result = result && (prop(a) == prop(b));

            check(x => x.CurrentStation);
            check(x => x.CurrentStationIndex);
            check(x => x.Stations);

            // check(x => x.IsPlaying);
            // check(x => x.PlayEngine);

            return result;

        }
    }
}
